<template>
	<view class="box">
		<!-- 诊所详情 -->
		<view class="details">
			<swiper class="swipers" @change="swiperChange" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
			 :duration="duration">
				<swiper-item class="items" v-for="(item,index) in list.image_url" :key="item.id">
					<image :src="item" mode="scaleToFill" style="width: 750rpx; height: 500rpx;"></image>
				</swiper-item>
			</swiper>
			<!-- 自定义指示灯 -->
			<view class="indicatorLight">
				<text v-for="index in list.image_url.length" :class="currentIndex == index ? 'active': ''"></text>
			</view>

			<view class="content">
				<!-- 小横线 -->
				<view class="titleLine"></view>
				<view class="introduce">
					<view>
						<view class="thearde">
							<text>{{list.service_title}}</text>
						</view>
						<view class="julikm">
						</view>
						<view class="cishu">
						</view>
					</view>
					<view class="address">
						<image src="../../../static/image/qita/positions.png" mode="scaleToFill" style="width: 22rpx; height: 28rpx;"></image>
						<text>地址：{{list.address_title}}</text>
					</view>
					<text>{{list.synopsis}}</text>
				</view>

				<view class="licences">
					<view class="licencesOne" @click="licencesOne">
						<image src="../../../static/image/qita/duixiang.png" mode="scaleToFill" style="width: 28rpx; height: 34rpx;"></image>
						<text>医疗执业许可证</text>
						<image class="xiaojiantou" src="../../../static/image/qita/xiaojiantou.png" mode="scaleToFill" style="width: 12rpx; height: 20rpx;"></image>
					</view>
					<view class="licencesTow" @click="licencesTow">
						<image src="../../../static/image/qita/duixiang.png" mode="scaleToFill" style="width: 28rpx; height: 34rpx;"></image>
						<text>营业执照</text>
						<image class="xiaojiantou" src="../../../static/image/qita/xiaojiantou.png" mode="scaleToFill" style="width: 12rpx; height: 20rpx;"></image>
					</view>
				</view>

				<!-- 医生详情 -->
				<view class="doctorDetails">
					<veiw class="xiaoludians"><text>医生详情</text><text></text>
						<!-- <image @click="moredoctors" src="/static/image/qita/xiaojiantou.png" mode="scaleToFill" style="width: 12rpx; height: 20rpx;"></image> -->
					</veiw>
					<view class="doctors" v-for="(item,index) in details" :key="item.id">
						<view class="imgs">
							<image :src="item.user_url" mode="scaleToFill" style="width: 100rpx; height: 100rpx;"></image>
						</view>
						<view class="txts">
							<text>{{item.user_name}}</text>
							<text v-if="item.user_sex == 1">男</text>
							<text v-else>女</text>
							<text>{{item.holder}}</text>
							<!-- <text class="likeyuyueanniu">立即咨询</text> -->
							<text>{{item.referral}}</text>
						</view>
					</view>
				</view>

				<!-- 项目套餐 -->
				<view class="meal">
					<view class="xiaoludians"><text>项目套餐</text>
						<!-- <image src="/static/image/qita/xiaojiantou.png" mode="scaleToFill" style="width: 12rpx; height: 20rpx;"></image> -->
					</view>
					<view class="promeal" v-for="(item,index) in ItemsArr" :key="item.id" @click="jumpProjectDetails(index)">
						<image :src="item.image_url"></image>
						<view class="xiugaiyuyue">
							<text>{{item.items_title}}</text>
							<text>{{item.content}}</text>
							<text>￥{{item.price}}</text>
							<!-- <text id="yuyuecishu">预约数：<text id="cishus">{{item.sub_num}}</text></text> -->
						</view>
					</view>
				</view>


			</view>
		</view>
		<!-- 点击按钮 -->
		<view class="joinDetails" @click="joinExamine" v-show="!jiaru">
			<text>加入</text>
		</view>

	</view>
</template>

<script>
	export default {
		onLoad(options) {
			this.jiaru = options.id;
			this.ids = this.$store.state.service_id || options.id;
			this.getClinic(this.ids);
			this.getDoctors(this.ids);
			this.getItems(this.ids);
		},
		data() {
			return {
				makeappointment: false,
				// 诊所的id号
				ids: null,

				// 轮播图的功能
				indicatorDots: false,
				autoplay: true,
				interval: 2000,
				duration: 500,

				// 指示灯的下标
				currentIndex: 0,

				// 诊所的Id号
				detailId: null,
				list: null,
				details: null,
				selectProject: null,
				ItemsArr: null,

				// 选择到店时间
				arrive_time: "",
				
				// 如果options里面有id时,就不能显示加入按钮了
				jiaru: null,
			};
		},
		methods: {
			joinExamine() {
				uni.redirectTo({
					url: "../material2/material2"
				});
			},
			jumpNew1() {
				uni.navigateTo({
					url: "../news/news"
				});
			},
			swiperChange(e) {
				this.currentIndex = e.target.current; //获取当前轮播图片的下标, 可以给当前指示点加样式
			},
			licencesOne() {
				let arr = [];
				arr.push(this.list.licence_url);
				uni.previewImage({
					urls: arr,
					loop: true,
					success() {
						console.log(`预览成功了...`)
					},
					fail() {
						console.log(`失败了吧`)
					}
				});
			},
			licencesTow() {
				let arr = [];
				arr.push(this.list.trading_url);
				uni.previewImage({
					urls: arr,
					success() {
						console.log(`预览成功了...`)
					},
					fail(err) {
						console.log(err);
						console.log(`失败了吧`)
					}
				});
			},
			moredoctors() {
				uni.navigateTo({
					url: `../cliniclist/cliniclist?cliniclist=${encodeURIComponent(JSON.stringify(this.details))}`
				})
			},
			projectPackage() {
				uni.navigateTo({
					url: `../moreProjects/moreProjects?project=${encodeURIComponent(JSON.stringify(this.ItemsArr))}&juli=${this.juli}`
				})
			},
			appointmentNow() {
				this.makeappointment = true;
				this.selectProject = this.ItemsArr[0];
			},
			hideappointment() {
				this.makeappointment = false;
			},
			xuanzhexianmu(index) {
				this.selectProject = this.ItemsArr[index];
			},
			jumpmyAppointment() {
				this.getAppointmentNow();
			},
			jumpProjectDetails(index) {
				let juli = (this.juli / 1000).toFixed(2);
				uni.navigateTo({
					url: `../projectDetails/projectDetails?id=${this.ItemsArr[index].id}&juli=${juli}`
				});
			},

			async getClinic(id) {
				const res = await this.$myrequest({
					url: `Service/servicePreview?id=${id}`,
				});
				this.list = res.data.data;
				console.log(`==========`)
				console.log(this.list);
				console.log(`----------`)
			},

			async getDoctors(id) {
				let Doctors = await this.$myrequest({
					url: `Service/getDoctor?id=${id}`,
				});
				console.log(`=======`)
				console.log(Doctors);
				console.log(`=======`)
				this.details = Doctors.data.data;
			},

			async getItems(id) {
				const Items = await this.$myrequest({
					url: `Service/getItems?id=${id}`,
				});
				this.ItemsArr = Items.data.data;
			},
			// 立即预约
			async getAppointmentNow() {
				// 没有openid时成功提示信息后，并跳转到登录页面
				if (!this.$store.state.userinfo) {
					uni.showToast({
						title: "请求点击登录",
						duration: 1000,
						success: (res) => {
							setTimeout(() => {
								uni.switchTab({
									url: "../tab/my/my"
								})
							}, 1010)
						}
					})
					return false;
				};
				let openids = this.$store.state.userinfo.openid;
				console.log("=====", this.arrive_time);
				if (this.arrive_time == null || this.arrive_time == "") {
					uni.showToast({
						title: "请选择时间"
					});
					return false;
				};
				let Items = await this.$myrequest({
					url: `Subscribe/addSubscribe`,
					method: "POST",
					data: {
						service_id: this.ids,
						item_id: this.selectProject.id,
						openid: openids,
						arrive_time: this.arrive_time
					}
				});
				let urls = `../appointmentSsuccessful/appointmentSsuccessful?id=${this.ids}`;
				if (Items.data.code == 201) {
					urls =
						`../myappointment/myappointment?page=1&datas=${encodeURIComponent(JSON.stringify(this.selectProject))}&ids=${this.ids}&names=${this.list.service_title}`;
				};
				this.makeappointment = false;
				uni.navigateTo({
					url: urls,
				})
			},
			// 拨打电话
			makeCall() {
				uni.makePhoneCall({
					phoneNumber: this.list.contact_phone
				});
			},
			// 到店时间的选择
			show() {
				if (!this.disableds) {
					this.$refs.picker.show();
				};
			},
			confirm(e) {
				this.arrive_time = e.detail.value;
			},

		}
	}
</script>
<style lang="scss">
	.details {
		@include outSideBox;

		.swipers {
			width: 750rpx;
			height: 400rpx;
			position: relative;

			.items {
				width: 100%;
			}
		}

		.indicatorLight {
			@include shuiping;
			top: 300rpx;

			text {
				display: inline-block;
				width: 12rpx;
				height: 12rpx;
				border-radius: 50%;
				background-color: #A9A7A3;

				&:not(:last-of-type) {
					margin-right: 14rpx;
				}
			}

			// 当处于激活状态时就显示该颜色
			.active {
				background-color: #FFFFFF !important
			}
		}

		.content {
			width: 750rpx;
			height: calc(100vh - 500rpx);
			position: absolute;
			bottom: 0;
			left: 0;
			z-index: 2;
			background-color: RGBA(255, 255, 255, 1);
			border-radius: 30rpx 30rpx 0 0;
			padding: 50rpx 0 0 0;

			.introduce {
				padding: 0 25rpx;
				padding-bottom: 25rpx;

				>view {
					&:first-of-type {
						@include chuizhilianduan;
					}
				}
			}

			.licences {
				width: calc(100vw - 60rpx);
				display: flex;
				justify-content: center;
				align-items: center;
				flex-wrap: wrap;
				border-top: 1rpx solid RGBA(229, 229, 229, 1);
				margin: 0 auto;

				>view {
					width: 100%;
					height: 80rpx;
					line-height: 80rpx;

					>image {
						width: 30rpx;
						height: 30rpx;
						vertical-align: middle;
						margin-right: 24rpx;
					}
				}
			}

			// 项目
			.meal {
				margin: 30rpx 0;
				padding: 0 30rpx;
				padding-bottom: 80rpx;
				position: relative;

				// 项目套餐
				.promeal {
					display: flex;
					margin: 20rpx 0;
					height: 180rpx;

					image {
						width: 240rpx;
						height: 100%;
						border-radius: 10rpx;
					}

					view {
						padding-left: 30rpx;
						height: 100%;
						display: flex;
						flex-wrap: wrap;

						>text {
							width: 100%;

							&:first-of-type {
								color: rgba(0, 0, 0, 1);
								font-size: 28rpx;
							}

							&:nth-of-type(2) {
								color: RGBA(159, 159, 159, 1);
								font-size: 22rpx;
							}

							&:nth-of-type(3) {
								color: RGBA(255, 100, 9, 1);
								font-size: 34rpx;
							}
						}
					}
				}
			}

			// 医生详情
			.doctorDetails {
				margin: 60rpx 30rpx;
				position: relative;

				&::after,
				&::before {
					position: absolute;
					display: block;
					content: "";
					width: 100vw;
					height: 10rpx;
					left: -30rpx;
					background-color: rgba(237, 237, 237, 1);
				}

				&::after {
					top: -36rpx;
				}

				&::before {
					bottom: -36rpx;
				}

				.doctors {
					display: flex;
					height: 180rpx;
					padding: 40rpx;
					padding-left: 0rpx;
					// justify-content: center;
					align-items: center;
					padding-bottom: 30rpx;

					&:not(:last-of-type) {
						border-bottom: 1rpx solid rgba(232, 233, 235, 1);
					}

					.imgs {
						width: 100rpx;
						height: 100rpx;

						image {
							border-radius: 50%;
						}
					}

					.txts {
						padding-left: 30rpx;
						height: 100%;
						display: flex;
						flex-wrap: wrap;
						@include chuizhilianduan;

						>text {
							&:not(:nth-of-type(4)) {
								@include shuipingchuijuzhong;
							}

							&:first-of-type {
								display: inline-block;
								width: 135rpx;
								font-size: 35rpx;
								color: rgba(0, 0, 0, 1);
							}

							&:nth-of-type(2) {
								color: rgba(102, 102, 102, 1);
								// margin: 0 30rpx 0 40rpx;
							}

							&:nth-of-type(3) {
								display: inline-block;
								text-align: center;
								width: 100rpx;
								font-size: 20rpx;
								transform: translateY(10%);
								margin-left: 20rpx;
								color: rgba(58, 206, 176, 1);
								position: relative;

								&::before {
									display: block;
									content: "";
									width: 120%;
									height: 36rpx;
									border: 2rpx solid rgba(58, 206, 176, 1);
									border-radius: 50rpx;
									background-color: transparent;
									position: absolute;
									top: 50%;
									left: 50%;
									transform: translate(-50%, -53%);
								}
							}

							&:last-of-type {
								width: 512rpx;
								font-size: 22rpx;
								color: RGBA(210, 209, 210, 1);
							}
						}
					}

				}
			}
		}
	}

	.address {
		image {
			vertical-align: middle;
			margin-right: 28rpx;
		}

		>text {
			color: #808080;
			font-size: 26rpx !important;
			font-family: PingFang SC;
			font-weight: 400;
			color: rgba(1, 0, 0, 1) !important;
		}

		padding-bottom: 30rpx;
		border-bottom: 1prx solid #000000;
	}

	.xiaoludians {
		&::before {
			display: block;
			content: "";
			width: 8rpx;
			height: 24rpx;
			background-color: #41D6B8;
			border-radius: 50rpx;
			position: absolute;
			top: 50%;
			left: 0;
			transform: translateY(-50%);
		}

		position: relative;
		padding-left: 30rpx;
		@include chuizhilianduan;
		padding-right: 30rpx;

		text {
			&:nth-of-type(2) {
				color: #999999;
				font-size: 24rpx;
				margin-left: 415rpx;
			}
		}
	}


	.likeyuyue {
		position: fixed;
		bottom: 0rpx;
		left: 0rpx;
		width: 750rpx;
		height: 106rpx;
		display: flex;
		padding-bottom: 20rpx;
		background-color: #FFFFFF;

		>view {
			@include shuipingchuijuzhong;
			flex-wrap: wrap;

			&:first-of-type {
				width: 90rpx;
				margin-left: 53rpx;
				padding-top: 15rpx;

				>text {
					font-size: 18rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: rgba(179, 179, 179, 1);
				}
			}

			&:nth-of-type(2) {
				width: 90rpx;
				margin-left: 10rpx;
				padding-top: 15rpx;

				>text {
					display: inline-block;
					width: 100%;
					text-align: center;
					font-size: 18rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: rgba(179, 179, 179, 1);
				}
			}

			&:last-of-type {
				margin-left: 20rpx;
				width: 450rpx;
				height: 86rpx;
				background: linear-gradient(90deg, rgba(96, 232, 205, 1), rgba(45, 209, 188, 1));
				box-shadow: 3rpx 4rpx 20rpx 4rpx rgba(15, 170, 150, 0.1);
				border-radius: 43rpx;

				text {
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: rgba(255, 255, 255, 1);
				}
			}
		}
	}

	// 小箭头样式
	.licencesOne,
	.licencesTow {
		position: relative;

		.xiaojiantou {
			position: absolute;
			top: 50%;
			right: 0;
			transform: translateY(-50%);
		}
	}

	.likeyuyueanniu {
		width: 126rpx;
		height: 46rpx;
		background-color: #2DD1BC;
		border-radius: 50rpx;
		font-size: 22rpx;
		margin-left: 50rpx;
		color: rgba(255, 255, 255, 1);
	}

	.xiugaiyuyue {
		position: relative;
	}

	#yuyuecishu {
		position: absolute;
		bottom: 20rpx;
		left: 315rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: #9F9F9F;

		#cishus {
			color: #2DD1BC !important;
		}
	}

	.makeappointment {
		width: 750rpx;
		height: 100vh;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 200;

		.apponins {
			height: 884rpx;
			width: 100%;
			position: absolute;
			background-color: #FFFFFF;
			bottom: 0;
			left: 0;
			z-index: 202;
			padding: 30rpx;

			.tupiantou {
				display: flex;
				justify-content: center;

				.tupian {
					@include shuipingchuijuzhong;
				}

				.prices {
					margin-left: 40rpx;
					width: 100%;

					>text {
						&:first-of-type {
							display: inline-block;
							color: rgba(255, 50, 34, 1);
							width: 100%;
							font-size: 32rpx;
						}

						&:nth-of-type(2) {
							text {
								color: #2DD1BC;
							}
						}
					}

					.projectPrice {
						display: inline-block;
						padding-top: 40rpx;
						color: #999999;
					}
				}
			}

			.xianmu {
				margin-top: 30rpx;
				display: flex;
				flex-wrap: wrap;

				.service {
					font-size: 26rpx;
					color: #000000;
				}

				>text {
					&:first-of-type {
						display: inline-block;
						width: 100%;
					}

					&:not(:first-of-type) {
						margin-left: 20rpx;
						margin-top: 20rpx;
						display: inline-block;
						padding: 10rpx;
						border: 2rpx solid #999999;
						border-radius: 50rpx;
						font-size: 26rpx;
						color: #999999;
					}
				}
			}
		}

		.hideappointment {
			height: 100vh;
			width: 100%;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 201;
			background-color: rgba(178, 178, 178, .5);
		}
	}

	.xuanzheanniu {
		@include dibuanniu;
		width: 689rpx;
	}

	.thearde {
		text {
			font-size: 34rpx;
			color: #000000;
		}
	}

	.julikm {
		margin-left: 120rpx;

		image {
			margin-right: 10rpx;
		}

		text {
			color: #010000;
		}
	}

	.cishu {
		margin-right: 10rpx;

		>text {
			color: #010000 !important;
		}

		.subNum {
			margin-left: 20rpx;
			color: #2DD1BC
		}
	}

	// 到店时间
	.daodian {
		@include chuizhilianduan;
		margin-top: 30rpx;
	}

	.jiantou {
		font-size: 26rpx;
		color: #999999;

		.daodianjiantou {
			margin-left: 40rpx;
		}
	}

	// 点击按钮
	.joinDetails {
		width: 340rpx;
		@include dibuanniu;
		z-index: 1000;
	}
</style>
